console.log('------- sw-test -------: ', this);

this.addEventListener('install', function(event) {
    console.log('--event: ', event);
    console.log('--caches: ', caches);

    event.waitUntil(
        caches.open('v1').then(function(cache) {
            console.log('--cache: ', cache);
            return cache.addAll(['./app.js']);
        })
    );
});

this.addEventListener('fetch', function(event) {
    event.respondWith(
        caches
            .match(event.request)
            .then(function() {
                return fetch(event.request).then(function(response) {
                    console.log('----response: ', response);
                    // return caches.open('v1').then(function(cache) {
                    //     cache.put(event.request, response.clone());
                    //     return response;
                    // });
                });
            })
            .catch(function() {
                // return caches.match('/sw-test/gallery/myLittleVader.jpg');
            })
    );
});
